package tool

type MyQueue[T MyInt] struct {
	head *Node1[T]
	tail *Node1[T]
	Size T
}

func (receiver *MyQueue[T]) QueueSize() T {
	return receiver.Size
}

func (receiver *MyQueue[T]) IsEmpty() bool {
	return receiver.Size == 0
}
func (receiver *MyQueue[T]) Offer(v T) {
	var n = Node1[T]{Value: v, Next: nil}
	if receiver.head == nil {
		receiver.head = &n
		receiver.tail = &n
	} else {
		receiver.tail.Next = &n
		receiver.tail = &n
	}

	receiver.Size++
}
func (receiver *MyQueue[T]) Poll() T {
	var v T = -1
	if receiver.Size == 0 {
		receiver.head, receiver.tail = nil, nil

	} else if receiver.Size == 1 {
		v = receiver.head.Value
		receiver.head = nil
		receiver.tail = nil
		receiver.Size--

	} else {
		v = receiver.head.Value
		receiver.head = receiver.head.Next
		receiver.Size--
	}
	return v

}
func (receiver MyQueue[T]) Peek() T {
	var v T = -1

	if receiver.head != nil {
		v = receiver.head.Value
	}

	return v
}
